#include <iostream>
#include <cmath>
#include "../inc/Utils.hxx"
#include <cstdlib>

using namespace std;

int Utils::RANGE_BINS_COUNT = calculateRangeBinsCount();

int Utils::RANGE_BIN_LENGTH = calculateRangeBinLength();

vector<double> Utils::linspace(double start, double end, int n) {
    vector<double> result;
    double step = (end-start)/(n-1);
    while(start <= end) {
        result.push_back(start);
        start += step;
    }
    return result;
}

complex<double> Utils::getWGN() {
    srand(rdtsc());
    double rnd1 = (double)rand()/RAND_MAX;
    srand(rdtsc());
    double rnd2 = (double)rand()/RAND_MAX;
    //box muller
    double phi = 2*M_PI*rnd2;
    double real = sqrt(-2*log(rnd1))*cos(phi); 
    double imag = sqrt(-2*log(rnd1))*sin(phi);
    return complex<double>(real, imag);    
}

unsigned long Utils::rdtsc() {
    unsigned int lo, hi;
    __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
    return ((unsigned long long) hi << 32) | lo;
}

int Utils::calculateRangeBinsCount() {
//    double rangeLightTime = (double)Transmitter::RADAR_RANGE/Utils::LIGHT_SPEED;
//    double result = rangeLightTime*Receiver::SAMPLING_FREQUENCY;
//    return abs(result);    
        return 1000;
}

int Utils::calculateRangeBinLength() {
    return 15; 
}
